﻿
$(document).ready(function () {
    layui.use(['table', 'dropdown'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var dropdown = layui.dropdown;
        ///财务类别下拉框
        $.ajax({
            url: "/Finance/GetFinanceType",
            data: {
                Token: localStorage.getItem("token")
            },
            type: "get",
            success: function (res) {
                var ss = JSON.parse(res)
                var ssdate = ss.data;
                if (Array.isArray(ssdate) && ssdate.length > 0) {
                    var selectHtml = '<option value="">请选择</option>';
                    ssdate.forEach(function (item) {
                        selectHtml += `<option value=${item.financeTypeId}>${item.fRremark}</option>`
                    })
                    //更新Select元素的html
                    $('#FinanceTypeId').html(selectHtml);

                    //渲染
                    form.render('select');
                }
                else {
                    console.warn('返回 ssdate 为空或不是有效的数组', ssdate);
                }
            }
        })

        function renderTable(pageNum) {
            // 从查询框获取条件
            var dto = {
                PageIndex: 1,
                PageSize: 100,
                SerialNumber: $("#SerialNumber").val(),
                ReceivableName: $("#ReceivableName").val(),
                FinanceTypeId: $("#FinanceTypeId").val(),
                Payer: $("#Payer").val(),
                Kdate: $("#Kdate").val(),
                Sdate: $("#Sdate").val(),
                ReceivableState: $("#ReceivableState").val(),
                ToKen: localStorage.getItem("token"),
                User_Id: 1,
                Office_Id: '1'
            }
            // 发送Ajax请求
            $.ajax({
                url: '/Finance/GetFinancialReceivable',  // 这里填上你的后端接口地址
                type: 'GET',
                data: dto,
                dataType: 'json',
                success: function (response) {
                    var data = JSON.parse(response)
                    //console.log(data.data.list)
                    // 渲染表格
                    table.render({
                        elem: '#dataTable',
                        cols: [[
                            { type: 'checkbox', fixed: 'left' },
                            { field: 'serialNumber', width: 110, title: '流水号', align: 'center' },
                            { field: 'receivableName', width: 110, align: 'center', title: '名称' },
                            { field: 'financeTypeName', width: 110, align: 'center', title: '分类' },
                            { field: 'payer', width: 110, align: 'center', title: '付款方' },
                            { field: 'receivableAmount', width: 110, align: 'center', title: '应收金额' },
                            { field: 'paymentPrice', width: 110, align: 'center', title: '实收金额' },
                            { field: 'residueMoney', width: 110, align: 'center', title: '剩余金额' },
                            {
                                field: 'receivableState', width: 105, align: 'center', title: '状态', templet: function (d) {
                                    if (d.receivableState == 1) {
                                        return '<span style="color: blue">待审核</span>';
                                    } else if (d.receivableState == 2) {
                                        return '<span style="color: red">审核通过</span>';
                                    } else if (d.receivableState == 3) {
                                        return '<span style="color: pink">审核失败</span>';
                                    } else if (d.receivableState == 4) {
                                        return '<span style="color: orange">部分付款</span>';
                                    } else if (d.receivableState == 5) {
                                        return '<span style="color: green">全部付款</span>';
                                    }
                                }
                            },
                            { field: 'addTime', width: 150, align: 'center', title: '创建时间', templet: '<div>{{ layui.util.toDateString(d.addTime, "yyyy-MM-dd HH:mm:ss") }}</div>', },
                            {
                                fixed: 'right', title: '操作', width: 250, align: 'center', minWidth: 125, templet: function (d) {
                                    if (d.receivableState == 1) {
                                        return '<a style="color: blue" class="layui-icon layui-icon-edit" onclick="UpdFinanceRece(' + d.receivableId + ')">编辑</a>&nbsp;<a style="color: blue" class="layui-icon layui-icon-delete" onclick="DelFinanceRece(' + d.receivableId + ')">删除</a>&nbsp;<a style="color: blue" class="layui-icon layui-icon-eye" onclick="Cha(' + d.receivableId + ')">查看</a>&nbsp;<a style="color: blue" class="layui-icon layui-icon-survey" onclick="Shen(' + d.receivableId + ')">审核</a> '
                                    } else if (d.receivableState == 2) {
                                        return '<a style="color: blue" class="layui-icon layui-icon-rmb" onclick="Shou(' + d.receivableId + ')">收款</a>&nbsp;<a style="color: blue" class="layui-icon layui-icon-eye" onclick="Cha(' + d.receivableId + ')">查看</a>';
                                    } else if (d.receivableState == 3) {
                                        return '<a style="color: blue" class="layui-icon layui-icon-edit" onclick="UpdFinanceRece(' + d.receivableId + ')">编辑</a>&nbsp;<a style="color: blue" class="layui-icon layui-icon-delete" onclick="DelFinanceRece(' + d.receivableId + ')">删除</a>&nbsp;<a style="color: blue" class="layui-icon layui-icon-eye" onclick="Cha(' + d.receivableId + ')">查看</a>&nbsp;<a style="color: blue" class="layui-icon layui-icon-survey" onclick="Shen(' + d.receivableId + ')">审核</a>';
                                    } else if (d.receivableState == 4) {
                                        return '<a style="color: blue" class="layui-icon layui-icon-rmb" onclick="Shou(' + d.receivableId + ')">收款</a>&nbsp;<a style="color: blue" class="layui-icon layui-icon-eye" onclick="Cha(' + d.receivableId + ')">查看</a>';
                                    } else if (d.receivableState == 5) {
                                        return '<a style="color: blue" class="layui-icon layui-icon-eye" onclick="Cha(' + d.receivableId + ')">查看</a>';
                                    }
                                },
                            }
                        ]],
                        data: data.data.list,  // 数据源
                        toolbar: '#toolbarDemo',
                        defaultToolbar: ['exports'],

                    });
                },
                error: function (xhr, status, error) {
                    console.log('请求失败: ' + error);
                }
            });

            ////////////选择复选框之后的数据////////////////////////////////////////////////
            document.getElementById('getCheckData').onclick = function () {
                // 获取所有勾选的行数据
                var checkedData = table.checkStatus('dataTable').data;
                // 提取选中数据的ID
                var checkedIds = checkedData.map(function (item) {
                    //console.log(item)
                    return item.receivableId;  // 获取每一行的id
                });
                // 输出选中的ID
                //console.log(checkedIds);
                var currentDate = new Date();
                var deldto = {
                    ids: checkedIds,
                    delName: "朱泊霖",
                    delTime: currentDate.getFullYear() + '-' + (currentDate.getMonth() + 1) + '-' + currentDate.getDate() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes(),
                    Token: localStorage.getItem("token")
                }
                //console.log(deldto);
                if (deldto.ids.length == 0) {
                    layer.msg('批量删除至少选择一项');
                    return
                }
                layer.confirm('你真的要批量删除吗？', { icon: 3 }, function () {
                    $.ajax({
                        url: "/Finance/DelFinanceReces",
                        data: deldto,
                        type: "post",
                        success: function (res) {
                            //console.log(res)
                            var s = JSON.parse(res)
                            if (s.data > 0) {
                                layer.msg('批量删除成功', { icon: 0 }, function () {
                                    //layer.msg('提示框关闭后的回调');
                                    location.reload()
                                });
                            }
                            else {
                                layer.msg('批量删除失败');
                                return
                            }
                        }
                    })
                }, function () {
                    layer.msg('取消批量删除');
                })

            }

            ////////////选择复选框编辑////////////////////////////////////////////////
            document.getElementById('piUpd').onclick = function () {
                // 获取所有勾选的行数据
                var checkedData = table.checkStatus('dataTable').data;
                // 提取选中数据的ID
                var checkedIds = checkedData.map(function (item) {
                    //console.log(item)
                    return item.receivableId;  // 获取每一行的id
                });
                if (checkedData.length == 0) {
                    layer.msg('编辑至少选择一项');
                    return
                }
                if (checkedData.length >= 2) {
                    layer.msg('编辑只能选择一项');
                    return
                }
                var obj = {
                    receivableId: '',
                    serialNumber: '',
                    receivableName: '',
                    financeTypeId: '',
                    lastpaydate: '',
                    payer: '',
                    beneficiary: '',
                    receivableAmount: '',
                    paymentPrice: '',
                    residueMoney: '',
                    paymentNum: '',
                    receivableState: '',
                    rRremark: '',
                    office_Id: '',
                    user_Id: '',
                    addName: '',
                    addTime: '',
                    updName: '',
                    updTime: ''
                }
                ///财务类别下拉框
                $.ajax({
                    url: "/Finance/GetFinanceType",
                    data: {
                        Token: localStorage.getItem("token")
                    },
                    type: "get",
                    success: function (res) {
                        var ss = JSON.parse(res)
                        var ssdate = ss.data;
                        if (Array.isArray(ssdate) && ssdate.length > 0) {
                            var selectHtml = '<option value="">请选择</option>';
                            ssdate.forEach(function (item) {
                                selectHtml += `<option value=${item.financeTypeId}>${item.fRremark}</option>`
                            })
                            //更新Select元素的html
                            $('#FinanceTypeIds').html(selectHtml);

                            //渲染
                            form.render('select');
                        }
                        else {
                            console.warn('返回 ssdate 为空或不是有效的数组', ssdate);
                        }
                    }
                })

                ////反填
                $.ajax({
                    url: "/Finance/FanFinanceRece",
                    data: {
                        id: checkedIds[0],
                        Token: localStorage.getItem("token")
                    },
                    type: "get",
                    success: function (res) {
                        var data = JSON.parse(res)
                        console.log(data)
                        $(data.data).each(function () {
                            $("#receivableId").val(this.receivableId)
                            $("#serialNumber").val(this.serialNumber)
                            $("#receivableName").val(this.receivableName)

                            //显示下拉框
                            $("#FinanceTypeIds").val(this.financeTypeId)
                            form.render('select')

                            //反填日期框
                            var da = new Date(this.lastpaydate);
                            // 获取年、月、日
                            var year = da.getFullYear();
                            var month = (da.getMonth() + 1).toString().padStart(2, '0');  // 月份从0开始，因此加1
                            var day = da.getDate().toString().padStart(2, '0');  // 补充两位数字
                            // 拼接成 "yyyy-MM-dd" 格式
                            var formattedDate = `${year}-${month}-${day}`;
                            $("#lastpaydate").val(formattedDate)

                            $("#payer").val(this.payer)
                            $("#beneficiary").val(this.beneficiary)
                            $("#receivableAmount").val(this.receivableAmount)
                            $("#paymentPrice").val(this.paymentPrice)
                            $("#residueMoney").val(this.residueMoney)
                            $("#paymentNum").val(this.paymentNum)
                            $("#receivableState").val(this.receivableState)
                            $("#rRremark").val(this.rRremark)
                            $("#office_Id").val(this.office_Id)
                            $("#user_Id").val(this.user_Id)
                            $("#addName").val(this.addName)
                            $("#addTime").val(this.addTime)
                            $("#updName").val(this.updName)
                            $("#updTime").val(this.updTime)

                            var currentDate = new Date();
                            obj.receivableId = this.receivableId;
                            obj.serialNumber = this.serialNumber;
                            obj.receivableName = this.receivableName;

                            obj.financeTypeId = this.financeTypeId;
                            obj.lastpaydate = this.lastpaydate;
                            obj.payer = this.payer;
                            obj.beneficiary = this.beneficiary;
                            obj.receivableAmount = this.receivableAmount;
                            obj.paymentPrice = this.paymentPrice;
                            obj.residueMoney = this.residueMoney;
                            obj.paymentNum = this.paymentNum;
                            obj.receivableState = this.receivableState;
                            obj.rRremark = this.rRremark;
                            obj.office_Id = this.office_Id;
                            obj.user_Id = this.user_Id;
                            obj.addName = this.addName;
                            obj.addTime = this.addTime;
                            obj.updName = '朱柏霖';
                            obj.updTime = currentDate.getFullYear() + '-' + (currentDate.getMonth() + 1) + '-' + currentDate.getDate() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes();
                        })
                    }

                })

                //打开弹框
                layer.open({
                    type: 1,
                    area: '450px',
                    resize: false,
                    shadeClose: true,
                    title: '修改应收管理',
                    content: `
                    <form class="layui-form" action="">
                        <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
                            <div class="demo-login-container">
                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        流水号： <input type="text" name="serialNumber" id="serialNumber" value="" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div class="layui-input-inline">
                                        名称：<input type="text" lay-verify="required" name="receivableName" id="receivableName" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        类别：<select name="FinanceTypeIds" id="FinanceTypeIds" lay-filter="aihao">
                                           
                                        </select>
                                    </div>
                                    <div class="layui-input-inline">
                                        最后付款日：
                                        <div class="layui-input-prefix">
                                            <i class="layui-icon layui-icon-date"></i>
                                        </div>
                                        <input type="date" name="lastpaydate" id="lastpaydate" lay-verify="date" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        付款方：<input type="text" lay-verify="required" name="payer" id="payer" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div class="layui-input-inline">
                                        收款方：<input type="text" lay-verify="required" name="beneficiary" id="beneficiary" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        应收金额：<input type="text" lay-verify="required" name="receivableAmount" id="receivableAmount" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div class="layui-input-inline">
                                        付款次数：<input type="text" lay-verify="required" name="paymentNum" id="paymentNum" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>


                                <div class="layui-form-inline">
                                    <div class="layui-input-wrap">
                                        备注：<input type="text" id="rRremark" name="rRremark"  autocomplete="off" class="layui-textarea"  lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-loginss">修改</button>
                                </div>

                            </div>
                        </div>
                    </form>`,
                    success: function () {

                        // 对弹层中的表单进行初始化渲染
                        var dto = {
                            receivableId: '',
                            serialNumber: '',
                            receivableName: '',
                            financeTypeId: '',
                            lastpaydate: '',
                            payer: '',
                            beneficiary: '',
                            receivableAmount: '',
                            paymentPrice: '',
                            residueMoney: '',
                            paymentNum: '',
                            receivableState: '',
                            rRremark: '',
                            office_Id: '',
                            user_Id: '',
                            addName: '',
                            addTime: '',
                            updName: '',
                            updTime: '',
                            Token: localStorage.getItem("token")
                        }
                        form.render();
                        form.on('submit(demo-loginss)', function (dates) {
                            var field = dates.field; // 获取表单字段值
                            var times = new Date();
                            //赋值
                            dto.receivableId = obj.receivableId;
                            dto.serialNumber = field.serialNumber;
                            dto.receivableName = field.receivableName;
                            dto.financeTypeId = field.FinanceTypeIds;
                            dto.lastpaydate = field.lastpaydate;
                            dto.payer = field.payer;
                            dto.beneficiary = field.beneficiary;
                            dto.receivableAmount = field.receivableAmount;
                            dto.paymentPrice = obj.paymentPrice;
                            dto.residueMoney = obj.residueMoney;
                            dto.paymentNum = field.paymentNum;
                            dto.receivableState = obj.receivableState;
                            dto.rRremark = field.rRremark;
                            dto.office_Id = obj.office_Id;
                            dto.user_Id = obj.user_Id;
                            dto.addName = obj.addName;
                            dto.addTime = obj.addTime;
                            dto.updName = obj.updName;
                            dto.updTime = obj.updTime;
                            dto.Token = localStorage.getItem("token")
                            console.log(dto)
                            $.ajax({
                                url: "/Finance/UpdFinanceReceType",
                                data: dto,
                                type: "put",
                                success: function (res) {
                                    var ss = JSON.parse(res)
                                    console.log(res)
                                    if (ss.data > 0) {
                                        layer.msg('修改成功', { icon: 0 }, function () {
                                            location.reload()
                                        });
                                    }
                                    else if (ss.data == -1) {
                                        layer.msg('类别名称已存在，不能修改');
                                        return
                                    }
                                    else {
                                        layer.msg('修改失败');
                                        return
                                    }
                                }
                            })
                            return false; // 阻止默认 form 跳转
                        });
                    }
                });

            }
        };
        // 监听全选操作
        form.on('checkbox(check-all)', function (data) {
            var checked = data.elem.checked;  // 获取全选复选框的状态
            table.checkStatus('dataTable').isAll = checked;  // 设置是否全选
            form.render('checkbox');  // 重新渲染表单
        });

        ////////////删除////////////////////////////////////////////////
        window.DelFinanceRece = function (id) {
            var currentDate = new Date();
            var delres = {
                ids: id,
                delName: '朱泊霖',
                delTime: currentDate.getFullYear() + '-' + (currentDate.getMonth() + 1) + '-' + currentDate.getDate() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes(),
                Token: localStorage.getItem("token")
            };
            console.log(delres)
            layer.confirm('你真的要删除吗？', { icon: 3 }, function () {
                $.ajax({
                    url: "/Finance/DelFinanceReces",
                    data: delres,
                    type: "post",
                    success: function (daa) {
                        var s = JSON.parse(daa)
                        if (s.data == 1) {
                            layer.msg('删除成功', { icon: 0 }, function () {
                                location.reload()
                            });
                        }
                        else {
                            layer.msg('删除失败');
                            return
                        }
                    }
                })
            }, function () {
                layer.msg('取消删除');
            });





        }

        ////////////修改////////////////////////////////////////////////
        var obj = {
            receivableId: '',
            serialNumber: '',
            receivableName: '',
            financeTypeId: '',
            lastpaydate: '',
            payer: '',
            beneficiary: '',
            receivableAmount: '',
            paymentPrice: '',
            residueMoney: '',
            paymentNum: '',
            receivableState: '',
            rRremark: '',
            office_Id: '',
            user_Id:'',
            addName: '',
            addTime: '',
            updName: '',
            updTime: ''
        }
        window.UpdFinanceRece = function (id) {
            ///财务类别下拉框
            $.ajax({
                url: "/Finance/GetFinanceType",
                data: {
                    Token: localStorage.getItem("token")
                },
                type: "get",
                success: function (res) {
                    var ss = JSON.parse(res)
                    var ssdate = ss.data;
                    if (Array.isArray(ssdate) && ssdate.length > 0) {
                        var selectHtml = '<option value="">请选择</option>';
                        ssdate.forEach(function (item) {
                            selectHtml += `<option value=${item.financeTypeId}>${item.fRremark}</option>`
                        })
                        //更新Select元素的html
                        $('#FinanceTypeIds').html(selectHtml);

                        //渲染
                        form.render('select');
                    }
                    else {
                        console.warn('返回 ssdate 为空或不是有效的数组', ssdate);
                    }
                }
            })

            ////反填
            $.ajax({
                url: "/Finance/FanFinanceRece",
                data: {
                    id: id,
                    Token: localStorage.getItem("token")
                },
                type: "get",
                success: function (res) {
                    var data = JSON.parse(res)
                    console.log(data)
                    $(data.data).each(function () {
                        $("#receivableId").val(this.receivableId)
                        $("#serialNumber").val(this.serialNumber)
                        $("#receivableName").val(this.receivableName)

                        //显示下拉框
                        $("#FinanceTypeIds").val(this.financeTypeId)
                        form.render('select')
                        
                        //反填日期框
                        var da = new Date(this.lastpaydate);
                        // 获取年、月、日
                        var year = da.getFullYear();
                        var month = (da.getMonth() + 1).toString().padStart(2, '0');  // 月份从0开始，因此加1
                        var day = da.getDate().toString().padStart(2, '0');  // 补充两位数字
                        // 拼接成 "yyyy-MM-dd" 格式
                        var formattedDate = `${year}-${month}-${day}`;
                        $("#lastpaydate").val(formattedDate)

                        $("#payer").val(this.payer)
                        $("#beneficiary").val(this.beneficiary)
                        $("#receivableAmount").val(this.receivableAmount)
                        $("#paymentPrice").val(this.paymentPrice)
                        $("#residueMoney").val(this.residueMoney)
                        $("#paymentNum").val(this.paymentNum)
                        $("#receivableState").val(this.receivableState)
                        $("#rRremark").val(this.rRremark)
                        $("#office_Id").val(this.office_Id)
                        $("#user_Id").val(this.user_Id)
                        $("#addName").val(this.addName)
                        $("#addTime").val(this.addTime)
                        $("#updName").val(this.updName)
                        $("#updTime").val(this.updTime)

                        var currentDate = new Date();
                        obj.receivableId = this.receivableId;
                        obj.serialNumber = this.serialNumber;
                        obj.receivableName = this.receivableName;

                        obj.financeTypeId = this.financeTypeId;
                        obj.lastpaydate = this.lastpaydate;
                        obj.payer = this.payer;
                        obj.beneficiary = this.beneficiary;
                        obj.receivableAmount = this.receivableAmount;
                        obj.paymentPrice = this.paymentPrice;
                        obj.residueMoney = this.residueMoney;
                        obj.paymentNum = this.paymentNum;
                        obj.receivableState = this.receivableState;
                        obj.rRremark = this.rRremark;
                        obj.office_Id = this.office_Id;
                        obj.user_Id = this.user_Id;
                        obj.addName = this.addName;
                        obj.addTime = this.addTime;
                        obj.updName = '朱柏霖';
                        obj.updTime = currentDate.getFullYear() + '-' + (currentDate.getMonth() + 1) + '-' + currentDate.getDate() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes();
                    })
                }

            })


            layer.open({
                type: 1,
                area: '450px',
                resize: false,
                shadeClose: true,
                title: '修改应收管理',
                content: `
                    <form class="layui-form" action="">
                        <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
                            <div class="demo-login-container">
                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        流水号： <input type="text" name="serialNumber" id="serialNumber" value="" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div class="layui-input-inline">
                                        名称：<input type="text" lay-verify="required" name="receivableName" id="receivableName" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        类别：<select name="FinanceTypeIds" id="FinanceTypeIds" lay-filter="aihao">
                                           
                                        </select>
                                    </div>
                                    <div class="layui-input-inline">
                                        最后付款日：
                                        <div class="layui-input-prefix">
                                            <i class="layui-icon layui-icon-date"></i>
                                        </div>
                                        <input type="date" name="lastpaydate" id="lastpaydate" lay-verify="date" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        付款方：<input type="text" lay-verify="required" name="payer" id="payer" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div class="layui-input-inline">
                                        收款方：<input type="text" lay-verify="required" name="beneficiary" id="beneficiary" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        应收金额：<input type="text" lay-verify="required" name="receivableAmount" id="receivableAmount" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div class="layui-input-inline">
                                        付款次数：<input type="text" lay-verify="required" name="paymentNum" id="paymentNum" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>


                                <div class="layui-form-inline">
                                    <div class="layui-input-wrap">
                                        备注：<input type="text" id="rRremark" name="rRremark"  autocomplete="off" class="layui-textarea"  lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-loginss">修改</button>
                                </div>

                            </div>
                        </div>
                    </form>`,
                success: function () {

                    // 对弹层中的表单进行初始化渲染
                    var dto = {
                        receivableId: '',
                        serialNumber: '',
                        receivableName: '',
                        financeTypeId: '',
                        lastpaydate: '',
                        payer: '',
                        beneficiary: '',
                        receivableAmount: '',
                        paymentPrice: '',
                        residueMoney: '',
                        paymentNum: '',
                        receivableState: '',
                        rRremark: '',
                        office_Id: '',
                        user_Id: '',
                        addName: '',
                        addTime: '',
                        updName: '',
                        updTime: '',
                        Token: localStorage.getItem("token")
                    }
                    form.render();
                    form.on('submit(demo-loginss)', function (dates) {
                        var field = dates.field; // 获取表单字段值
                        var times = new Date();
                        //赋值
                        dto.receivableId = obj.receivableId;
                        dto.serialNumber = field.serialNumber;
                        dto.receivableName = field.receivableName;
                        dto.financeTypeId = field.FinanceTypeIds;
                        dto.lastpaydate = field.lastpaydate;
                        dto.payer = field.payer;
                        dto.beneficiary = field.beneficiary;
                        dto.receivableAmount = field.receivableAmount;
                        dto.paymentPrice = obj.paymentPrice;
                        dto.residueMoney = obj.residueMoney;
                        dto.paymentNum = field.paymentNum;
                        dto.receivableState = obj.receivableState;
                        dto.rRremark = field.rRremark;
                        dto.office_Id = obj.office_Id;
                        dto.user_Id = obj.user_Id;
                        dto.addName = obj.addName;
                        dto.addTime = obj.addTime;
                        dto.updName = obj.updName;
                        dto.updTime = obj.updTime;
                        dto.Token = localStorage.getItem("token")
                        console.log(dto)
                        $.ajax({
                            url: "/Finance/UpdFinanceReceType",
                            data: dto,
                            type: "put",
                            success: function (res) {
                                var ss = JSON.parse(res)
                                console.log(res)
                                if (ss.data > 0) {
                                    layer.msg('修改成功', { icon: 0 }, function () {
                                        location.reload()
                                    });
                                }
                                else if (ss.data == -1) {
                                    layer.msg('类别名称已存在，不能修改');
                                    return
                                }
                                else {
                                    layer.msg('修改失败');
                                    return
                                }
                            }
                        })
                        return false; // 阻止默认 form 跳转
                    });
                }
            });







        }

        // 初次加载表格数据
        renderTable(1);

        // 查询按钮点击事件
        $('#searchBtn').click(function () {
            renderTable(1);  // 重置为第一页，并重新加载数据
        });

        // 获取选中数据按钮
        $('#getSelected').click(function () {
            var checkStatus = table.checkStatus('dataTable');
            var selectedData = checkStatus.data;  // 获取选中的数据
            console.log(selectedData);  // 打印选中的数据
        });

        //////////////新增//////////////////////////////////////////////////
        layui.use(function () {
            var $ = layui.$;
            var layer = layui.layer;
            var util = layui.util;
            var form = layui.form;

            // 事件
            util.on('lay-on', {
                'test-page-custom1': function () {
                    layer.open({
                        type: 1,
                        area: '450px',
                        resize: false,
                        shadeClose: true,
                        title: '新增应收管理',
                        content: `
                    <form class="layui-form" action="">
                        <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
                            <div class="demo-login-container">
                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        流水号： <input type="text" name="serialNumber" id="serialNumber" value="" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div class="layui-input-inline">
                                        名称：<input type="text" lay-verify="required" name="receivableName" id="receivableName" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        类别：<select name="FinanceTypeIds" id="FinanceTypeIds" lay-filter="aihao">
                                           
                                        </select>
                                    </div>
                                    <div class="layui-input-inline">
                                        最后付款日：
                                        <div class="layui-input-prefix">
                                            <i class="layui-icon layui-icon-date"></i>
                                        </div>
                                        <input type="date" name="lastpaydate" id="lastpaydate" lay-verify="date" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        付款方：<input type="text" lay-verify="required" name="payer" id="payer" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div class="layui-input-inline">
                                        收款方：<input type="text" lay-verify="required" name="beneficiary" id="beneficiary" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        应收金额：<input type="text" lay-verify="required" name="receivableAmount" id="receivableAmount" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div class="layui-input-inline">
                                        付款次数：<input type="text" lay-verify="required" name="paymentNum" id="paymentNum" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-wrap">
                                        备注：<input type="text" id="rRremark" name="rRremark"  autocomplete="off" class="layui-textarea"  lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-login1">添加</button>
                                </div>

                            </div>
                        </div>
                    </form>`,
                        success: function () {
                            // 对弹层中的表单进行初始化渲染
                            form.render();
                            ///财务类别下拉框
                            $.ajax({
                                url: "/Finance/GetFinanceType",
                                data: {
                                    Token: localStorage.getItem("token")
                                },
                                type: "get",
                                success: function (res) {
                                    var ss = JSON.parse(res)
                                    var ssdate = ss.data;
                                    if (Array.isArray(ssdate) && ssdate.length > 0) {
                                        var selectHtml = '<option value="">请选择</option>';
                                        ssdate.forEach(function (item) {
                                            selectHtml += `<option value=${item.financeTypeId}>${item.fRremark}</option>`
                                        })
                                        //更新Select元素的html
                                        $('#FinanceTypeIds').html(selectHtml);

                                        //渲染
                                        form.render('select');
                                    }
                                    else {
                                        console.warn('返回 ssdate 为空或不是有效的数组', ssdate);
                                    }
                                }
                            })
                            // 表单提交事件
                            
                            var dto = {
                                receivableId: '',
                                serialNumber: '',
                                receivableName: '',
                                financeTypeId: '',
                                lastpaydate: '',
                                payer: '',
                                beneficiary: '',
                                receivableAmount: '',
                                paymentNum: '',
                                receivableState: '',
                                rRremark: '',
                                office_Id: '',
                                user_Id: '',
                                addTime : '',
                                addName: '',
                                Token: localStorage.getItem("token"),
                                paymentPrice:'',
                                residueMoney: '',
                            };
                            form.on('submit(demo-login1)', function (dates) {
                                var field = dates.field; // 获取表单字段值
                                var times = new Date();
                                //赋值
                                dto.serialNumber = field.serialNumber;
                                dto.receivableName = field.receivableName;
                                dto.financeTypeId = field.FinanceTypeIds;
                                dto.lastpaydate = field.lastpaydate;
                                dto.payer = field.payer;
                                dto.beneficiary = field.beneficiary;
                                dto.receivableAmount = field.receivableAmount;
                                dto.paymentNum = field.paymentNum;
                                dto.rRremark = field.rRremark;
                                dto.receivableState = '1';
                                dto.office_Id = '1';
                                dto.user_Id = 1;
                                dto.addName = '卢芳';
                                dto.paymentPrice = 0,
                                    dto.residueMoney =0,
                                dto.addTime = times.getFullYear() + '-' + (times.getMonth() + 1) + '-' + times.getDate() + ' ' + times.getHours() + ':' + times.getMinutes(),
                                    dto.Token = localStorage.getItem("token")
                                console.log(dto)
                                $.ajax({
                                    url: "/Finance/AddFinanceReceivable",
                                    data: dto,
                                    type: "post",
                                    success: function (res) {
                                        var ss = JSON.parse(res)
                                        if (ss.data >0) {
                                            layer.msg('添加成功', { icon: 0 }, function () {
                                                location.reload()
                                            });
                                        }
                                        else if (ss.data == -1) {
                                            layer.msg('类别名称已存在，不能添加');
                                            return
                                        }
                                        else {
                                            layer.msg('添加失败');
                                            return
                                        }
                                    }
                                })
                                return false; // 阻止默认 form 跳转
                            });
                        }
                    });
                }
            })
        });

        ////////////查看////////////////////////////////////////////////
        var objs = {
            receivableId: '',
            serialNumber: '',
            receivableName: '',
            financeTypeId: '',
            lastpaydate: '',
            payer: '',
            beneficiary: '',
            receivableAmount: '',
            paymentPrice: '',
            residueMoney: '',
            paymentNum: '',
            receivableState: '',
            rRremark: '',
            office_Id: '',
            user_Id: '',
            addName: '',
            addTime: '',
            updName: '',
            updTime: ''
        }
        window.Cha = function (id) {
            ///财务类别下拉框
            $.ajax({
                url: "/Finance/GetFinanceType",
                data: {
                    Token: localStorage.getItem("token")
                },
                type: "get",
                success: function (res) {
                    var ss = JSON.parse(res)
                    var ssdate = ss.data;
                    if (Array.isArray(ssdate) && ssdate.length > 0) {
                        var selectHtml = '<option value="">请选择</option>';
                        ssdate.forEach(function (item) {
                            selectHtml += `<option value=${item.financeTypeId}>${item.fRremark}</option>`
                        })
                        //更新Select元素的html
                        $('#FinanceTypeIds').html(selectHtml);

                        //渲染
                        form.render('select');
                    }
                    else {
                        console.warn('返回 ssdate 为空或不是有效的数组', ssdate);
                    }
                }
            })

            ////反填
            $.ajax({
                url: "/Finance/FanFinanceRece",
                data: {
                    id: id,
                    Token: localStorage.getItem("token")
                },
                type: "get",
                success: function (res) {
                    var data = JSON.parse(res)
                    console.log(data)
                    $(data.data).each(function () {
                        $("#receivableId").val(this.receivableId)
                        $("#serialNumber").val(this.serialNumber)
                        $("#receivableName").val(this.receivableName)

                        //显示下拉框
                        $("#FinanceTypeIds").val(this.financeTypeId)
                        form.render('select')

                        //反填日期框
                        var da = new Date(this.lastpaydate);
                        // 获取年、月、日
                        var year = da.getFullYear();
                        var month = (da.getMonth() + 1).toString().padStart(2, '0');  // 月份从0开始，因此加1
                        var day = da.getDate().toString().padStart(2, '0');  // 补充两位数字
                        // 拼接成 "yyyy-MM-dd" 格式
                        var formattedDate = `${year}-${month}-${day}`;
                        $("#lastpaydate").val(formattedDate)

                        $("#payer").val(this.payer)
                        $("#beneficiary").val(this.beneficiary)
                        $("#receivableAmount").val(this.receivableAmount)
                        $("#paymentPrice").val(this.paymentPrice)
                        $("#residueMoney").val(this.residueMoney)
                        $("#paymentNum").val(this.paymentNum)
                        $("#receivableState").val(this.receivableState)
                        $("#rRremark").val(this.rRremark)
                        $("#office_Id").val(this.office_Id)
                        $("#user_Id").val(this.user_Id)
                        $("#addName").val(this.addName)
                        $("#addTime").val(this.addTime)
                        $("#updName").val(this.updName)
                        $("#updTime").val(this.updTime)

                        var currentDate = new Date();
                        objs.receivableId = this.receivableId;
                        objs.serialNumber = this.serialNumber;
                        objs.receivableName = this.receivableName;

                        objs.financeTypeId = this.financeTypeId;
                        objs.lastpaydate = this.lastpaydate;
                        objs.payer = this.payer;
                        objs.beneficiary = this.beneficiary;
                        objs.receivableAmount = this.receivableAmount;
                        objs.paymentPrice = this.paymentPrice;
                        objs.residueMoney = this.residueMoney;
                        objs.paymentNum = this.paymentNum;
                        objs.receivableState = this.receivableState;
                        objs.rRremark = this.rRremark;
                        objs.office_Id = this.office_Id;
                        objs.user_Id = this.user_Id;
                        objs.addName = this.addName;
                        objs.addTime = this.addTime;
                        objs.updName = '朱柏霖';
                        objs.updTime = currentDate.getFullYear() + '-' + (currentDate.getMonth() + 1) + '-' + currentDate.getDate() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes();
                    })
                }

            })

            layer.open({
                type: 1,
                area: '450px',
                resize: false,
                shadeClose: true,
                title: '应收详情',
                content: `
                    <form class="layui-form" action="">
                        <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
                            <div class="demo-login-container">
                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        流水号： <input type="text" name="serialNumber" id="serialNumber" value="" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div class="layui-input-inline">
                                        名称：<input type="text" lay-verify="required" name="receivableName" id="receivableName" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        类别：<select name="FinanceTypeIds" id="FinanceTypeIds" lay-filter="aihao">
                                           
                                        </select>
                                    </div>
                                    <div class="layui-input-inline">
                                        最后付款日：
                                        <div class="layui-input-prefix">
                                            <i class="layui-icon layui-icon-date"></i>
                                        </div>
                                        <input type="date" name="lastpaydate" id="lastpaydate" lay-verify="date" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        付款方：<input type="text" lay-verify="required" name="payer" id="payer" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div class="layui-input-inline">
                                        收款方：<input type="text" lay-verify="required" name="beneficiary" id="beneficiary" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        应收金额：<input type="text" lay-verify="required" name="receivableAmount" id="receivableAmount" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div class="layui-input-inline">
                                        付款次数：<input type="text" lay-verify="required" name="paymentNum" id="paymentNum" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-wrap">
                                        备注：<input type="text" id="rRremark" name="rRremark"  autocomplete="off" class="layui-textarea"  lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-loginss1">确定</button>
                                </div>

                            </div>
                        </div>
                    </form>`,
                success: function () {
                    // 对弹层中的表单进行初始化渲染
                    form.render();
                    form.on('submit(demo-loginss1)', function (dates) {
                        location.reload();
                        return false; // 阻止默认 form 跳转
                    });
                }
            });







        }

        ////////////审批////////////////////////////////////////////////
        var objssd = {
            receivableId: '',
            serialNumber: '',
            receivableName: '',
            financeTypeId: '',
            lastpaydate: '',
            payer: '',
            beneficiary: '',
            receivableAmount: '',
            paymentPrice: '',
            residueMoney: '',
            paymentNum: '',
            receivableState: '',
            rRremark: '',
            office_Id: '',
            user_Id: '',
            addName: '',
            addTime: '',
            updName: '',
            updTime: ''
        }
        window.Shen = function (id) {

            ///财务类别下拉框
            $.ajax({
                url: "/Finance/GetFinanceType",
                data: {
                    Token: localStorage.getItem("token")
                },
                type: "get", 
                success: function (res) {
                    var ss = JSON.parse(res)
                    var ssdate = ss.data;
                    if (Array.isArray(ssdate) && ssdate.length > 0) {
                        var selectHtml = '<option value="">请选择</option>';
                        ssdate.forEach(function (item) {
                            selectHtml += `<option value=${item.financeTypeId}>${item.fRremark}</option>`
                        })
                        //更新Select元素的html
                        $('#FinanceTypeIds').html(selectHtml);

                        //渲染
                        form.render('select');
                    }
                    else {
                        console.warn('返回 ssdate 为空或不是有效的数组', ssdate);
                    }
                }
            })

            ////反填
            $.ajax({
                url: "/Finance/FanFinanceRece",
                data: {
                    id: id,
                    Token: localStorage.getItem("token")
                },
                type: "get",
                success: function (res) {
                    var data = JSON.parse(res)
                    console.log(data)
                    $(data.data).each(function () {
                        $("#receivableId").val(this.receivableId)
                        $("#serialNumber").val(this.serialNumber)
                        $("#receivableName").val(this.receivableName)

                        //显示下拉框
                        $("#FinanceTypeIds").val(this.financeTypeId)
                        form.render('select')

                        //反填日期框
                        var da = new Date(this.lastpaydate);
                        // 获取年、月、日
                        var year = da.getFullYear();
                        var month = (da.getMonth() + 1).toString().padStart(2, '0');  // 月份从0开始，因此加1
                        var day = da.getDate().toString().padStart(2, '0');  // 补充两位数字
                        // 拼接成 "yyyy-MM-dd" 格式
                        var formattedDate = `${year}-${month}-${day}`;
                        $("#lastpaydate").val(formattedDate)

                        $("#payer").val(this.payer)
                        $("#beneficiary").val(this.beneficiary)
                        $("#receivableAmount").val(this.receivableAmount)
                        $("#paymentPrice").val(this.paymentPrice)
                        $("#residueMoney").val(this.residueMoney)
                        $("#paymentNum").val(this.paymentNum)
                        $("#receivableState").val(this.receivableState)
                        $("#rRremark").val(this.rRremark)
                        $("#office_Id").val(this.office_Id)
                        $("#user_Id").val(this.user_Id)
                        $("#addName").val(this.addName)
                        $("#addTime").val(this.addTime)
                        $("#updName").val(this.updName)
                        $("#updTime").val(this.updTime)

                        var currentDate = new Date();
                        objs.receivableId = this.receivableId;
                        objs.serialNumber = this.serialNumber;
                        objs.receivableName = this.receivableName;

                        objs.financeTypeId = this.financeTypeId;
                        objs.lastpaydate = this.lastpaydate;
                        objs.payer = this.payer;
                        objs.beneficiary = this.beneficiary;
                        objs.receivableAmount = this.receivableAmount;
                        objs.paymentPrice = this.paymentPrice;
                        objs.residueMoney = this.residueMoney;
                        objs.paymentNum = this.paymentNum;
                        objs.receivableState = this.receivableState;
                        objs.rRremark = this.rRremark;
                        objs.office_Id = this.office_Id;
                        objs.user_Id = this.user_Id;
                        objs.addName = this.addName;
                        objs.addTime = this.addTime;
                        objs.updName = '朱柏霖';
                        objs.updTime = currentDate.getFullYear() + '-' + (currentDate.getMonth() + 1) + '-' + currentDate.getDate() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes();
                    })
                }

            })

            layer.open({
                type: 1,
                area: '500px',
                resize: false,
                shadeClose: true,
                title: '应收详情',
                content: `
                    <form class="layui-form" action="">
                        <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
                            <div class="demo-login-container">
                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        流水号： <input type="text" name="serialNumber" id="serialNumber" value="" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                     <div class="layui-input-inline">
                                        名称：<input type="text" lay-verify="required" name="receivableName" id="receivableName" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        类别：<select name="FinanceTypeIds" id="FinanceTypeIds" lay-filter="aihao">\
                                        </select>
                                    </div>
                                    <div class="layui-input-inline">
                                        最后付款日：
                                        <div class="layui-input-prefix">
                                            <i class="layui-icon layui-icon-date"></i>
                                        </div>
                                        <input type="date" name="lastpaydate" id="lastpaydate" lay-verify="date" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        付款方：<input type="text" lay-verify="required" name="payer" id="payer" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div class="layui-input-inline">
                                        收款方：<input type="text" lay-verify="required" name="beneficiary" id="beneficiary" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        应收金额：<input type="text" lay-verify="required" name="receivableAmount" id="receivableAmount" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div class="layui-input-inline">
                                        付款次数：<input type="text" lay-verify="required" name="paymentNum" id="paymentNum" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-wrap">
                                        备注：
                                        <input type="text" id="rRremark" name="rRremark"  autocomplete="off" class="layui-textarea"  lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-btn-container">
                                         <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm" lay-submit lay-filter="demo-logi1">取消</button>
                                         <button class="layui-btn layui-btn-sm" lay-submit lay-filter="demo-logi2">审核通过</button>
                                         <button class="layui-btn layui-btn-sm" lay-submit lay-filter="demo-logi3">审核不通过</button>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </form>`,
                success: function () {
                    // 对弹层中的表单进行初始化渲染
                    var dto = {
                        receivableId: '',
                        serialNumber: '',
                        receivableName: '',
                        financeTypeId: '',
                        lastpaydate: '',
                        payer: '',
                        beneficiary: '',
                        receivableAmount: '',
                        paymentPrice: '',
                        residueMoney: '',
                        paymentNum: '',
                        receivableState: '',
                        rRremark: '',
                        office_Id: '',
                        user_Id: '',
                        addName: '',
                        addTime: '',
                        updName: '',
                        updTime: '',
                        Token: localStorage.getItem("token")
                    }
                    // 对弹层中的表单进行初始化渲染
                    form.render();
                    //取消
                    form.on('submit(demo-logi1)', function (dates) {
                        //关闭弹窗
                        layer.closeAll();
                        //刷新页面
                        location.reload();
                    });
                    //审核通过
                    form.on('submit(demo-logi2)', function (dates) {
                        // 对弹层中的表单进行初始化渲染
                        var dto = {
                            receivableId: '',
                            serialNumber: '',
                            receivableName: '',
                            financeTypeId: '',
                            lastpaydate: '',
                            payer: '',
                            beneficiary: '',
                            receivableAmount: '',
                            paymentPrice: '',
                            residueMoney: '',
                            paymentNum: '',
                            receivableState: '',
                            rRremark: '',
                            office_Id: '',
                            user_Id: '',
                            addName: '',
                            addTime: '',
                            updName: '',
                            updTime: '',
                            Token: localStorage.getItem("token")
                        }
                        var field = dates.field; // 获取表单字段值
                        var times = new Date();
                        //赋值
                        dto.receivableId = objs.receivableId;
                        dto.serialNumber = objs.serialNumber;
                        dto.receivableName = objs.receivableName;
                        dto.financeTypeId = objs.financeTypeId;
                        dto.lastpaydate = objs.lastpaydate;
                        dto.payer = objs.payer;
                        dto.beneficiary = objs.beneficiary;
                        dto.receivableAmount = objs.receivableAmount;
                        dto.paymentPrice = objs.paymentPrice;
                        dto.residueMoney = objs.residueMoney;
                        dto.paymentNum = objs.paymentNum;
                        dto.receivableState = 2;
                        dto.rRremark = objs.rRremark;
                        dto.office_Id = objs.office_Id;
                        dto.user_Id = objs.user_Id;
                        dto.addName = objs.addName;
                        dto.addTime = objs.addTime;
                        dto.updName = objs.updName;
                        dto.updTime = objs.updTime;
                        dto.Token = localStorage.getItem("token")
                        console.log(dto)
                        $.ajax({
                            url: "/Finance/UpdFinanceReceType",
                            data: dto,
                            type: "put",
                            success: function (res) {
                                var ss = JSON.parse(res)
                                console.log(ss)
                                if (ss.data>0) {
                                    layer.msg('审核通过', { icon: 0 }, function () {
                                        location.reload()
                                    });
                                }
                                else {
                                    layer.msg('修改失败');
                                    return
                                }
                            }
                        })
                        //location.reload();
                        return false; // 阻止默认 form 跳转
                    });
                    //审核不通过
                    form.on('submit(demo-logi3)', function (dates) {
                        // 对弹层中的表单进行初始化渲染
                        var dto = {
                            receivableId: '',
                            serialNumber: '',
                            receivableName: '',
                            financeTypeId: '',
                            lastpaydate: '',
                            payer: '',
                            beneficiary: '',
                            receivableAmount: '',
                            paymentPrice: '',
                            residueMoney: '',
                            paymentNum: '',
                            receivableState: '',
                            rRremark: '',
                            office_Id: '',
                            user_Id: '',
                            addName: '',
                            addTime: '',
                            updName: '',
                            updTime: '',
                            Token: localStorage.getItem("token")
                        }
                        var field = dates.field; // 获取表单字段值
                        var times = new Date();
                        //赋值
                        dto.receivableId = objs.receivableId;
                        dto.serialNumber = objs.serialNumber;
                        dto.receivableName = objs.receivableName;
                        dto.financeTypeId = objs.financeTypeId;
                        dto.lastpaydate = objs.lastpaydate;
                        dto.payer = objs.payer;
                        dto.beneficiary = objs.beneficiary;
                        dto.receivableAmount = objs.receivableAmount;
                        dto.paymentPrice = objs.paymentPrice;
                        dto.residueMoney = objs.residueMoney;
                        dto.paymentNum = objs.paymentNum;
                        dto.receivableState = 3;
                        dto.rRremark = objs.rRremark;
                        dto.office_Id = objs.office_Id;
                        dto.user_Id = objs.user_Id;
                        dto.addName = objs.addName;
                        dto.addTime = objs.addTime;
                        dto.updName = objs.updName;
                        dto.updTime = objs.updTime;
                        dto.Token = localStorage.getItem("token")
                        console.log(dto)
                        $.ajax({
                            url: "/Finance/UpdFinanceReceType",
                            data: dto,
                            type: "put",
                            success: function (res) {
                                var ss = JSON.parse(res)
                                if (ss.data >0) {
                                    layer.msg('审核不通过成功', { icon: 0 }, function () {
                                        location.reload()
                                    });
                                }
                                else {
                                    layer.msg('修改不通过失败');
                                    return
                                }
                            }
                        })
                        //location.reload();
                        return false; // 阻止默认 form 跳转
                    });


                }
            });


        }

        ////////////收款////////////////////////////////////////////////
        var Shou = {
            paymentId:'',
            serialNumber: '',
            paymentName: '',
            financeTypeId: '',
            paymentTime: '',
            paymentPrice: '',
            residueMoney: '',
            paymentRemark: '',
            office_Id: '',
            user_Id: '',
            addName: '',
            addTime: ''
        }
        window.Shou = function (id) {
            ///财务类别下拉框
            $.ajax({
                url: "/Finance/GetFinanceType",
                data: {
                    Token: localStorage.getItem("token")
                },
                type: "get",
                success: function (res) {
                    var ss = JSON.parse(res)
                    var ssdate = ss.data;
                    if (Array.isArray(ssdate) && ssdate.length > 0) {
                        var selectHtml = '<option value="">请选择</option>';
                        ssdate.forEach(function (item) {
                            selectHtml += `<option value=${item.financeTypeId}>${item.fRremark}</option>`
                        })
                        //更新Select元素的html
                        $('#FinanceTypeIdss').html(selectHtml);

                        //渲染
                        form.render('select');
                    }
                    else {
                        console.warn('返回 ssdate 为空或不是有效的数组', ssdate);
                    }
                }
            })
            ////反填
            $.ajax({
                url: "/Finance/FanFinanceRece",
                data: {
                    id: id,
                    Token: localStorage.getItem("token")
                },
                type: "get",
                success: function (res) {
                    var data = JSON.parse(res)
                    //console.log(data)
                    $(data.data).each(function () {
                        $("#serialNumber").val(this.serialNumber)
                        Shou.serialNumber = this.serialNumber;
                    })
                }

            })

            layer.open({
                type: 1,
                area: '500px',
                resize: false,
                shadeClose: true,
                title: '新增实收',
                content: `
                    <form class="layui-form" action="">
                        <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
                            <div class="demo-login-container">
                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        流水号： <input type="text" name="serialNumber" id="serialNumber" value="" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                     <div class="layui-input-inline">
                                        付款机构：<input type="text" lay-verify="required" name="paymentName" id="paymentName" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        付款方式：<select name="FinanceTypeIdss" id="FinanceTypeIdss" lay-filter="aihao">
                                        </select>
                                    </div>
                                    <div class="layui-input-inline">
                                        最后付款日：
                                        <div class="layui-input-prefix">
                                            <i class="layui-icon layui-icon-date"></i>
                                        </div>
                                        <input type="date" name="paymentTime" id="paymentTime" lay-verify="date" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-wrap">
                                        付款金额：<input type="text" lay-verify="required" name="paymentPrice" id="paymentPrice" value="" lay-verify="required" placeholder="全部" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-wrap">
                                        备注：
                                        <input type="text" id="paymentRemark" name="paymentRemark"  autocomplete="off" class="layui-textarea"  lay-affix="clear">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-btn-container">
                                         <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm" lay-submit lay-filter="demo-logi1">取消</button>
                                         <button class="layui-btn layui-btn-sm" lay-submit lay-filter="demo-logi2">确定</button>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </form>`,
                success: function () {
                    // 对弹层中的表单进行初始化渲染
                    var dto = {
                        paymentId: '',
                        serialNumber: '',
                        paymentName: '',
                        financeTypeId: '',
                        paymentTime: '',
                        paymentPrice: '',
                        residueMoney: '',
                        paymentRemark: '',
                        office_Id: '',
                        user_Id: '',
                        addName: '',
                        addTime: '',
                        Token: localStorage.getItem("token")
                    }
                    // 对弹层中的表单进行初始化渲染
                    form.render();
                    form.on('submit(demo-logi1)', function (dates) {
                        //关闭弹窗
                        layer.closeAll();
                        //刷新页面
                        location.reload();
                    });
                    form.on('submit(demo-logi2)', function (dates) {
                        var field = dates.field; // 获取表单字段值
                        var times = new Date();
                        //赋值
                        dto.serialNumber = Shou.serialNumber;
                        dto.paymentName = field.paymentName;
                        dto.financeTypeId = field.FinanceTypeIdss;
                        dto.paymentTime = field.paymentTime;
                        dto.paymentPrice = field.paymentPrice;
                        dto.residueMoney = field.residueMoney;
                        dto.paymentPrice = field.paymentPrice;
                        dto.paymentRemark = field.paymentRemark;
                        dto.office_Id = 1;
                        dto.user_Id = 1;
                        dto.addName = 'admin';
                        dto.addTime = times.getFullYear() + '-' + (times.getMonth() + 1) + '-' + times.getDate() + ' ' + times.getHours() + ':' + times.getMinutes(),
                        dto.Token = localStorage.getItem("token")
                        //console.log(dto)
                        $.ajax({
                            url: "/Finance/AddFinancePay",
                            data: dto,
                            type: "post",
                            success: function (res) {
                                var ss = JSON.parse(res)
                                console.log(ss)
                                if (ss.data == 0) {
                                    layer.msg('实收成功', { icon: 0 }, function () {
                                        location.reload()
                                    });
                                }
                                else {
                                    layer.msg('添加失败');
                                    return
                                }
                            }
                        })
                        //location.reload();
                        return false; // 阻止默认 form 跳转
                    });

                }
            });


        }












    });
});